package com.archeanx.lib.http;


import android.arch.lifecycle.Lifecycle;
import android.arch.lifecycle.LifecycleOwner;


import com.uber.autodispose.AutoDispose;
import com.uber.autodispose.AutoDisposeConverter;
import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider;

public class AutoDisposeUtil {

    /**
     * Lifecycle.Event.ON_STOP 代表 当activity stop的时候，取消订阅
     */
    public static <T> AutoDisposeConverter<T> autoDispose(LifecycleOwner owner) {
        return AutoDispose.<T>autoDisposable(AndroidLifecycleScopeProvider.from(owner, Lifecycle.Event.ON_STOP));
    }

    /**
     * Lifecycle.Event.ON_DESTROY 代表 当activity Destroy的时候，取消订阅
     */
    public static <T> AutoDisposeConverter<T> autoDisposeToDestroy(LifecycleOwner owner) {
        return AutoDispose.<T>autoDisposable(AndroidLifecycleScopeProvider.from(owner, Lifecycle.Event.ON_DESTROY));
    }


}
